/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Negocio;

import javax.mail.*;
import javax.mail.internet.*;

/**
 *
 * @author Alvaro
 */
public class ManejadorEmail {

    public void EnviarEmail(Email email)
                throws AddressException, MessagingException {

        // Create a mail session
        java.util.Properties props = new java.util.Properties();
        props.put("mail.smtp.host", email.getSmtpHost());
        props.put("mail.smtp.port", ""+email.getSmtpPort());
        Session session = Session.getDefaultInstance(props, null);

        // Construct the message
        Message msg = new MimeMessage(session);
        msg.setFrom(new InternetAddress(email.getFrom()));
        msg.setRecipient(Message.RecipientType.TO, new InternetAddress(email.getTo()));
        msg.setSubject(email.getSubject());
        msg.setText(email.getContent());


        // Send the message
        Transport.send(msg);
    }
}
